import io
from picamera import PiCamera
import time
import numpy as np
import cv2
import search

camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 10

cnt=0
stream = io.BytesIO()
for frame in camera.capture_continuous(stream, format='jpeg', use_video_port=True):
    cnt=(cnt+1)%10
    data = np.fromstring(stream.getvalue(), dtype=np.uint8)
    image = cv2.imdecode(data,cv2.IMREAD_COLOR)
    dst=search.initial_process(image)
    cv2.imwrite("static/videos/video"+str(cnt)+".jpg",image)
    cv2.imwrite("static/pandas/panda"+str(cnt)+".jpg",dst)
    # cv2.imshow("image",image)
    # cv2.waitKey(20)
    stream.truncate()
    stream.seek(0)
